Skip to content

Concurrent tasks #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 19, 2025
Merged

Conversation

andrewMacmurray
Copy link
Contributor

@andrewMacmurray andrewMacmurray commented May 12, 2025

This adds concurrent tasks to gren. The existing Task api has been modified to:

  • Add Task.concurrent, which runs an array of tasks concurrently.
  • Make map2 run concurrently.
  • Remove map4, map5 in favour of andMap.

The existing Scheduler kernel implementation is largely unchanged but with the addition of a _Scheduler_concurrent helper that spawns multiple processes, handles collecting results and signalling errors.

Copy link
Member

@robinheghan robinheghan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: it works! This actually speed up compiling-the-compiler a tiny amount in my very limited test :) Great work!

That said, I think there are still a few tweaks that needs to be done.

@andrewMacmurray andrewMacmurray force-pushed the concurrent-tasks branch 9 times, most recently from 5a0a78d to dbf4acb Compare May 13, 2025 07:26
@andrewMacmurray andrewMacmurray force-pushed the concurrent-tasks branch 3 times, most recently from 880f5f9 to 2d3dccd Compare May 13, 2025 08:00
@andrewMacmurray andrewMacmurray force-pushed the concurrent-tasks branch 3 times, most recently from 44d3ae6 to 697858c Compare May 16, 2025 07:22
@andrewMacmurray andrewMacmurray changed the title WIP: Concurrent tasks Concurrent tasks May 16, 2025
@andrewMacmurray andrewMacmurray marked this pull request as ready for review May 16, 2025 07:49
@robinheghan robinheghan requested a review from blaix May 16, 2025 08:09
Copy link
Member

@robinheghan robinheghan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do a little better on the documentation, but the implementation and the tests look good to me.

Might be worth waiting on @blaix 's input before making changes.

@robinheghan
Copy link
Member

Would you mind adding your name to CONTRIBUTORS as well?

The scheduler queue starts to become very slow when a large number of tasks are in flight (Array.shift is O(n) as it needs to reindex the array every time an element is removed).

This modifies `_Scheduler_enqueue` to loop through the active procs and resetting the queue when done. Larger arrays (1M+) are now handled more efficiently.
This runs an array of tasks concurrently. If any of them fail the rest of the running tasks are cleaned up.
Because `map2` is now concurrent `Task.sequence` needs to be implemented using `andThen`.
map4+ become less useful as these are just chains of `andMap`. `andMap` runs concurrently as it's defined using `map2`.
@robinheghan
Copy link
Member

Thank you for your hard work on this, @andrewMacmurray <3

@robinheghan robinheghan merged commit 238bd76 into gren-lang:main May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants